Skip to content

tests: Cleanup candlepin container#224

Merged
spetrosi merged 1 commit intolinux-system-roles:mainfrom
spetrosi:cleanup-candlepin-container
Apr 25, 2025
Merged

tests: Cleanup candlepin container#224
spetrosi merged 1 commit intolinux-system-roles:mainfrom
spetrosi:cleanup-candlepin-container

Conversation

@spetrosi
Copy link
Copy Markdown
Contributor

@spetrosi spetrosi commented Apr 2, 2025

Enhancement: In always block, import a task to cleanup candlepin container in tests that import the task tests/tasks/setup_candlepin.yml, which starts candlepin container.

Reason: Candlepin container remains after test playbook finishes. If you remove container-selinux rpm, you got selinux denials because the container is running but selinux policies for containers are removed.

@spetrosi spetrosi requested review from ptoscano and richm as code owners April 2, 2025 15:09
@spetrosi
Copy link
Copy Markdown
Contributor Author

spetrosi commented Apr 2, 2025

[citest]

Comment thread tests/tasks/cleanup_candlepin_container.yml Outdated
@spetrosi spetrosi force-pushed the cleanup-candlepin-container branch from 9b93f3a to 918739c Compare April 2, 2025 15:50
@spetrosi
Copy link
Copy Markdown
Contributor Author

spetrosi commented Apr 2, 2025

[citest]

Comment thread tests/tasks/cleanup_candlepin_container.yml Outdated
@spetrosi spetrosi force-pushed the cleanup-candlepin-container branch from da8e1bb to 176bf97 Compare April 2, 2025 16:27
@spetrosi
Copy link
Copy Markdown
Contributor Author

spetrosi commented Apr 2, 2025

[citest]

1 similar comment
@spetrosi
Copy link
Copy Markdown
Contributor Author

spetrosi commented Apr 2, 2025

[citest]

@spetrosi spetrosi force-pushed the cleanup-candlepin-container branch from 176bf97 to 3d012f5 Compare April 2, 2025 16:42
@spetrosi
Copy link
Copy Markdown
Contributor Author

spetrosi commented Apr 2, 2025

[citest]

Comment thread tests/tasks/cleanup_candlepin_container.yml Outdated
@spetrosi spetrosi force-pushed the cleanup-candlepin-container branch from 3d012f5 to c73c4de Compare April 2, 2025 17:27
@spetrosi
Copy link
Copy Markdown
Contributor Author

spetrosi commented Apr 2, 2025

[citest]

@spetrosi spetrosi force-pushed the cleanup-candlepin-container branch from c73c4de to 6bf0844 Compare April 2, 2025 17:47
@spetrosi
Copy link
Copy Markdown
Contributor Author

spetrosi commented Apr 2, 2025

[citest]

@spetrosi spetrosi force-pushed the cleanup-candlepin-container branch from 6bf0844 to fe058c2 Compare April 3, 2025 11:01
@spetrosi
Copy link
Copy Markdown
Contributor Author

spetrosi commented Apr 3, 2025

[citest]

@spetrosi spetrosi force-pushed the cleanup-candlepin-container branch from fe058c2 to 8b0ef28 Compare April 3, 2025 11:18
@spetrosi
Copy link
Copy Markdown
Contributor Author

spetrosi commented Apr 3, 2025

[citest]

@spetrosi spetrosi force-pushed the cleanup-candlepin-container branch from 8b0ef28 to 025dd72 Compare April 3, 2025 11:31
@spetrosi
Copy link
Copy Markdown
Contributor Author

spetrosi commented Apr 3, 2025

[citest]

@spetrosi
Copy link
Copy Markdown
Contributor Author

spetrosi commented Apr 3, 2025

@ptoscano please take a look when you have time

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rename this file as "stop_candlepin.yml"

Copy link
Copy Markdown
Contributor Author

@spetrosi spetrosi Apr 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since in fact we stop the container to remove it, and since this is specifically for the podman container, I find it clearer to call the file remove_candlepin_container.

Comment thread tests/tasks/cleanup_candlepin_container.yml Outdated
Comment thread tests/tasks/cleanup_candlepin_container.yml Outdated
Comment thread tests/tasks/cleanup_candlepin_container.yml Outdated
Comment thread tests/tasks/cleanup_candlepin_container.yml Outdated
Comment thread tests/tasks/cleanup_candlepin_container.yml Outdated
Comment thread tests/tasks/cleanup_candlepin_container.yml Outdated
Comment thread tests/tasks/cleanup_candlepin_container.yml Outdated
Comment on lines +3 to +12
- name: Check if the candlepin container is started
command: podman container exists candlepin
register: __rhc_candlepin_cont_started
failed_when: false
changed_when: false

- name: Stop and potentionally remove Candlepin container
command: podman stop candlepin
when: __rhc_candlepin_cont_started.rc == 0
changed_when: true
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of these two tasks, simply use the existing Stop and remove Candlepin container task in setup_candlepin.yml, as it does exactly that.

@richm
Copy link
Copy Markdown
Contributor

richm commented Apr 8, 2025

@ptoscano re: removing the candlepin image from the local registry

  • tests should clean up all resources - you are correct that if this is an ephemeral machine, none of the cleanup steps are necessary - what we could do for performance is tag all of those tasks with tests::cleanup, then use --skip-tags tests::cleanup if the machine is ephermeral - but we definitely need the cleanup for the default case, which is non-ephemeral
  • leaving the container image may cause problems in multi-role tests e.g. the podman tests expect a system without any local containers or images

So ideally, the rhc tests could leave the candlepin image locally until after all of the rhc tests are run, then do any post-rhc tests cleanup, like removing the candlepin image. The problem is that we don't have a way to run a "cleanup-after-all-role-tests-are-completed.yml" playbook.

@ptoscano
Copy link
Copy Markdown
Collaborator

ptoscano commented Apr 8, 2025

what we could do for performance is tag all of those tasks with tests::cleanup, then use --skip-tags tests::cleanup if the machine is ephermeral - but we definitely need the cleanup for the default case, which is non-ephemeral

I'm fine with this. Could we also tweak tox-lsr (which spawns a new system) to also skip that tag by default?

The problem is that we don't have a way to run a "cleanup-after-all-role-tests-are-completed.yml" playbook.

I guess it also depends on how the tests are run, right? ie tox-lsr vs testing-farm vs something else.

@richm
Copy link
Copy Markdown
Contributor

richm commented Apr 8, 2025

what we could do for performance is tag all of those tasks with tests::cleanup, then use --skip-tags tests::cleanup if the machine is ephermeral - but we definitely need the cleanup for the default case, which is non-ephemeral

I'm fine with this. Could we also tweak tox-lsr (which spawns a new system) to also skip that tag by default?

It's pretty easy to add --skip-tags tests::cleanup to your tox qemu run invocation e.g. tox -e qemu-ansible-core-2.17 -- --image-name centos-10 --log-level debug --skip-tags tests::cleanup -- tests/tests_repositories.yml

There are other ways to use tox e.g. with --make-batch where you do not want to skip cleanup.

The problem is that we don't have a way to run a "cleanup-after-all-role-tests-are-completed.yml" playbook.

I guess it also depends on how the tests are run, right? ie tox-lsr vs testing-farm vs something else.

Right - if we wanted to add something like a "run setup before all role tests" and "run cleanup after all role tests" then we would have to change tox-lsr, testing farm test runner, and the downstream test runners.

when:
- '"candlepin" in __rhc_candlepin_container_stopped.stdout'

- name: Remove Candlepin container image
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@richm maybe let's not clean up the image? It won't affect anything, and re-downloading it with each test upstream is a waste of network bandwidth.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@richm maybe let's not clean up the image? It won't affect anything, and re-downloading it with each test upstream is a waste of network bandwidth.

Ok. That will affect the podman tests, in the scenarios where we run tests from multiple roles - the podman tests expect no images. I guess that means changing this PR to use __rhc_cleanup_image: false (or just omit __rhc_cleanup_image because the default is false)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix the podman tests to work if there are images on the system.

@spetrosi
Copy link
Copy Markdown
Contributor Author

[citest]

@spetrosi spetrosi force-pushed the cleanup-candlepin-container branch from 7c4afed to cfcda44 Compare April 16, 2025 17:28
Comment thread tests/tests_environments.yml Outdated
@richm
Copy link
Copy Markdown
Contributor

richm commented Apr 16, 2025

I think just get rid of __rhc_cleanup_image which isn't used anymore, and we can merge

@spetrosi spetrosi force-pushed the cleanup-candlepin-container branch from cfcda44 to 3ad822a Compare April 16, 2025 17:38
@spetrosi
Copy link
Copy Markdown
Contributor Author

I'd wait for Pino approval too

@spetrosi
Copy link
Copy Markdown
Contributor Author

[citest]

@spetrosi spetrosi requested a review from ptoscano April 17, 2025 06:05
Copy link
Copy Markdown
Collaborator

@ptoscano ptoscano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates! I added few more notes that IMHO simplify things a bit, and make the changes more consistent with the current tasks.

Additionally a minor nit common to all the files:

        - name: Clean up Candlepin container
          include_tasks: tasks/remove_candlepin_container.yml

I suggest Clean up Candlepin instead (mimicks the setup tasks), or even Tear down Candlepin (see my previous comment on the naming of the new task file).

Thanks!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this file now only stops candlepin, better name it stop_candlepin.yml, or maybe even better teardown_candlepin.yml (symmetric with "setup")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than two tasks, simply try to stop the container, and do not consider the missing container an error. In practice simply move here the single task Stop and remove Candlepin container as currently in setup_candlepin.yml.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now this doesn't work because setup_candlepin.yml has the step to remove the container just in case the container was running from the previous playbook. But role always cleans up the container, and this step would fail. Although, it's good to have the step in setup_candlepin.yml for the case when you are testing locally and might have some container running from the previous test.
I think it's better to keep it the Ansible way and keep the task. By importing the task we say bring the system to the state where this container is removed, whether it exists now or not.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean here: the existing task that tries to stop the candlepin container also takes care of not erroring out in case the container does not exist. Strictly speaking, doing first the existence check and then stopping it may be a minor TOCTOU issue: https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use.

Comment thread tests/tasks/remove_candlepin_container.yml Outdated
Comment thread tests/tasks/setup_candlepin.yml Outdated
@spetrosi spetrosi force-pushed the cleanup-candlepin-container branch 2 times, most recently from 2b558ee to 96c2daa Compare April 23, 2025 10:17
@spetrosi
Copy link
Copy Markdown
Contributor Author

[citest]

@spetrosi spetrosi force-pushed the cleanup-candlepin-container branch from 96c2daa to 4915a6d Compare April 23, 2025 10:57
@spetrosi spetrosi requested a review from ptoscano April 23, 2025 13:53
Copy link
Copy Markdown
Collaborator

@ptoscano ptoscano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates, a couple of final changes, and it should be ready.

Make sure to squash all the commits.

Comment thread tests/tasks/setup_candlepin.yml Outdated
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean here: the existing task that tries to stop the candlepin container also takes care of not erroring out in case the container does not exist. Strictly speaking, doing first the existence check and then stopping it may be a minor TOCTOU issue: https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use.

@spetrosi spetrosi force-pushed the cleanup-candlepin-container branch 3 times, most recently from 490b08c to 36a306e Compare April 24, 2025 11:03
In always block, in tests that import the task tests/tasks/setup_candlepin.yml,
import a task to cleanup candlepin container
@spetrosi spetrosi force-pushed the cleanup-candlepin-container branch from 36a306e to 0f59dc1 Compare April 24, 2025 11:04
@spetrosi spetrosi requested a review from ptoscano April 24, 2025 11:04
@spetrosi
Copy link
Copy Markdown
Contributor Author

[citest]

@spetrosi spetrosi merged commit 6ee2eae into linux-system-roles:main Apr 25, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants